# -*- coding: utf-8 -*-
# @Time : 2022/3/24 17:01

from src.Bugs.Database.bug_history_database import BugDataHistory
from Common.yaml_method import YamlMethod


class BugHistory:
    """
    获取缺陷操作日志接口
    """

    @staticmethod
    def bug_history(bug_id):
        """
        获取缺陷操作日志接口
        :param bug_id: 缺陷ID
        :return:
        """

        code = YamlMethod().read_data('code.yaml')['code']

        history_list = BugDataHistory.query.filter_by(bug_id=bug_id).order_by(BugDataHistory.update_time.desc()).all()

        history_dict_list = []
        for c in history_list:
            history_dict = {'bug_id': c.bug_id, 'update_key': c.update_key,
                            'update_time': c.update_time.strftime("%Y-%m-%d, %H:%M:%S"), 'update_user': c.update_user}
            history_dict_list.append(history_dict)

        res = {
            'code': code[0],
            'message': 'success',
            'data': history_dict_list
        }

        return res

